from flask import Blueprint,request,jsonify
from models.user import *
from util.myredis import r
echarts_bule = Blueprint("echarts",__name__)

@echarts_bule.route('/getecharts')
def getecharts():
    # select DATE_FORMAT(create_time,'%Y-%m-%d'),count(*) from user group by DATE_FORMAT(create_time,'%Y-%m-%d');//按天统计数据
    # select DATE_FORMAT(create_time,'%Y-%m-%d') month ,count(*) c from user group by month;//按天统计数据
    sql = db.session.execute("select DATE_FORMAT(create_time,'%Y-%m-%d') month ,count(*) c from user group by month")
    list = []
    for i in sql:
        list.append({'value':i.c,'name':i.month})
    return jsonify({'code':200,'data':list})


@echarts_bule.route('/getechart')
def getechart():
    sql = db.session.execute("select status, count(*) c from (select * from project  union all select * from project1  union all select * from project2)t where status in (0,3) group by status")
    list = []
    for i in sql:
        if i.status == int(3):
            name = "已完成"
        else:
            name = "未完成"

        list.append({'value':i.c,'name':name})
    return jsonify({'code':200,'data':list})
